<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Option Explicit %>
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8" />
<META NAME="copyright" CONTENT="Copyright 2009-2010 - Martechina Co.Ltd" />
<META NAME="Author" CONTENT="劢格机械(中国)  Www.Martechina.Com" />
<META NAME="Keywords" CONTENT="" />
<META NAME="Description" CONTENT="" />
<TITLE>企业信息列表</TITLE>
<link href="css.css" rel="stylesheet" type="text/css">
<script language="javascript" src="../inc/Admin.js"></script>
</HEAD>
<!--#include file="../inc/Const.asp" -->
<!--#include file="../inc/ConnSiteData.asp" -->
<!--#include file="CheckAdmin.asp"-->
<!--#include file="../inc/Template.asp" -->
<%
'cookie 验证
'if Instr(request.cookies("Martech_com")("AdminPurview"),"|2,")=0 then 
'  response.write ("<font color='red')>你不具有该管理模块的操作权限，请返回！</font>")
'  response.end
'end if

'session 验证
if Instr(session("AdminPurview"),"|2,")=0 then 
  response.write ("<font color='red')>你不具有该管理模块的操作权限，请返回！</font>")
  response.end
end if
'========判断是否具有管理权限
%>
<BODY>
<table border="0" cellspacing="1" cellpadding="4" bgcolor="#FFFFFF" align="center" width="100%">
  <tr>
 <td height="27" colspan="4" align="center" class="classtop"><strong>模板列表</strong></td>
</tr>
  <tr class=classtd>
    <td width="50%" height="24" >
<%
'# 定义
dim Url,npage,ltype,ntype
	ntype	= LCase(request.querystring("type"))
	ltype	= LCase(Request.QueryString("to"))
	Url		= LCase(Request.ServerVariables("Script_Name"))
'# GET取值
Select Case ltype
	Case"data_skin"						: Call dataskin()		'# 模板管理
	Case Else							: Call dataskin()			'# 默认页面
End Select

'－－－－－－－－－－－－－－－－－－模板部分－－－－－－－－－－－－－－－－－－－－－－－
'# 模板列表
sub dataskin()
	Echo "<div id=""content"">"
	Echo "<div class=""skin"">"
	Dim Fso,Root,F,thumb,html
	Set Fso = Server.Createobject(strobjectfso)
	Set Root = Fso.GetFolder(Server.Mappath(installdir & "template/"))'模板路径
	For Each F In Root.SubFolders
	If (Fso.FileExists(Server.Mappath(installdir & "template/"&F.name&"/skin.xml"))) Then	'存在XML数据才列出来
		Dim objDom,SkinName,SkinDesigner,pubDate,DesignerURL,Version						'读取XML
		Set objDom = Server.CreateObject("Microsoft.XMLDOM") 
			objDom.async = false 
			objDom.load(Server.Mappath(installdir & "template/"&F.name&"/skin.xml")) 
			SkinName		= objDom.documentElement.selectSingleNode("//SkinName").text
			SkinDesigner	= objDom.documentElement.selectSingleNode("//SkinDesigner").text
			pubDate			= objDom.documentElement.selectSingleNode("//pubDate").text
			DesignerURL		= objDom.documentElement.selectSingleNode("//DesignerURL").text
			Version			= objDom.documentElement.selectSingleNode("//Version").text
		set objDom = Nothing
		If (Fso.FileExists(Server.Mappath(installdir & "template/"&F.name&"/skin.jpg"))) Then'存在缩略图
			thumb = "<a href=""?to=data_skin&skinname="&F.name&""" title=""使用该模板""><img src="""&installdir & "template/"&F.name&"/skin.jpg""></a>"
		Else
			thumb = "<a href=""?to=data_skin&skinname="&F.name&""" title=""使用该模板""><img src="""&installdir & "images/noskin.jpg""></a>"
		End if
		If indexskin= LCase(F.name) Then
			Echo "<ul id=""def"">"
				Else
			Echo "<ul>"
		End if	
			Echo "<li style=""float:left;"">"&thumb&"</li>"
			Echo "<li>路径："&F.name&"</b></li>"
			If indexskin= LCase(F.name) Then
			Echo "<li>名称："&SkinName&"<em> 使用中</em></li>"
			Else
			Echo "<li>名称：<a href=""?to=data_skin&skinname="&F.name&""" title=""使用该模板"">"&SkinName&"</a></li>"
			End if
			Echo "<li>作者：<a href="""&DesignerURL&""" title=""去作者网站看看～"" target=""_blank"">"&SkinDesigner&"</a></li>"
			Echo "<li>时间："&pubDate&"</li>"
			Echo "<li>版本："&Version&"</li>"
			Echo "</ul>"
	End if
	Next
	set Root = nothing
	Set Fso = Nothing
	Echo "</div>"
	Echo "</div>"

Dim skinurl,skininfo
	skinurl=LCase(Request.QueryString("skinname"))
If Len(skinurl)>0 Then
skininfo=getfile(installdir & "inc/Template.asp")		'读取设置文件
skininfo=editfile(skininfo,"indexskin",skinurl,0)	'替换关键内容
Call createfile(skininfo,installdir & "inc/Template.asp")	'写入文件
Go url&"?to=data_skin"
End If
End Sub

'# ECHO
Function Echo(byval str)
	response.write str
End Function

'# GO
Function Go(byval url)
    If url=-1 Then
		response.redirect request.servervariables("http_referer")
	Else
		response.redirect url
	End if
End Function

' 创建文件
Sub createfile(byval content,byval filedir)
Dim objStream
Set objStream = Server.CreateObject(strobjectads) 
    With objStream 
   .Open
   .Charset = "utf-8" 
   .Position = objStream.Size 
   .WriteText=content
   .SaveToFile server.mappath(filedir),2  
   .Close 
   End With 
Set objStream = Nothing 
end Sub 

' 读取文件
Public function getfile(byval filename)
	dim obj
	on error resume next
	set obj = server.createobject(strobjectads)
	obj.Type = 2
	obj.Mode = 3
	obj.open
	obj.Charset = "utf-8"
	obj.Position = obj.Size
	obj.Loadfromfile server.mappath(filename)
	getfile = obj.ReadText
	obj.close
	set obj = nothing
end Function

Function editfile(ByRef iContent,iVarName,ByVal iVarValue,iVarType)
	Dim objRegExp
	Set objRegExp=New RegExp
	objRegExp.IgnoreCase =True
	objRegExp.Global=True
	if iVarType=0 then iVarValue=""""&Replace(iVarValue,"""","""""")&""""
	objRegExp.Pattern="(\r\n|\n)(([ |\t]*)"&iVarName&"([ |\t]*)=([ |\t]*))(.+?)(\r\n|\n)"
	If objRegExp.Test(iContent)=True Then
		iContent=objRegExp.Replace(iContent,"$1$2"&iVarValue&"$7")
		editfile=iContent
		Exit Function
	End If
	editfile=iContent
End Function
%>
</td>
  </tr>
</table>
</body>
</html>